// 按钮权限菜单
import { Module } from 'vuex';
import { RootState } from '../index'


export interface ButtonState {
    buttonlist: string[]
}


export const buttonState: Module<ButtonState, RootState> = {
    namespaced: true,
    state: (): ButtonState => ({
        buttonlist: []
    }),
    mutations: {
        addButton(state: ButtonState, buttons) {
            state.buttonlist = buttons
        }
    },
    getters: {
        getBuuttons: state => state.buttonlist
    },
    actions: {
        generateButtons({ commit, state }, buttons: string[]) {
            // 过滤路由 
            let buttonlist: string[] = []
            buttons.forEach(button => {
                // match(/:/g)? 查询 : 出现过几次
                if (button.match(/:/g)?.length === 3) {
                    buttonlist.push(button)
                }
            })
            console.log(buttonlist);
            // 添加
            commit('addButton', buttonlist)
        }
    }
}